#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <map>
#include <algorithm>
using namespace std;

void FacetookPriorityWall(vector<string> names, vector<int> priority)
{
	unsigned i, j, sz;
	sz = priority.size();
	for(i = 0; i < sz; i++)
		for(j = i+1; j < sz; j++)
		{
			string str;
			int pri;
			if(priority[i] < priority[j] || ((priority[i] == priority[j]) && (names[i].compare(names[j]) > 0)))
			{
				str = names[j];
				names[j] = names[i];
				names[i] = str;
				pri = priority[j];
				priority[j] = priority[i];
				priority[i] = pri;
			}
		}

	for(i = 0; i < sz; i++)
		cout << names[i] << endl;
}

int vector_find(vector<string> v, string elem)
{
	vector<string>::iterator it;
	for(it = v.begin(); it != v.end(); it++)
	{
		if(*it == elem)
			return it - v.begin();
	}
	return -1;
}

int main(int argc, char* argv[])
{
	string name;
	int num;
	cin >> name >> num;
	
	vector<string> names;
	vector<int> priority;
	while(num)
	{
		//cout << endl << "num = " << num;
		unsigned numOfWords = 0;
		string name1,name2,action;
		cin >> name1 >> action;

		//cout << endl << "name1 = " << name1 << " action = " << action;

		unsigned score = 0;
		if(action == "posted")
		{
			numOfWords = 5;
			score = 15;
		}
		else if(action == "commented")
		{
			numOfWords = 5;
			score = 10;
		}
		else
		{
			numOfWords = 4;
			score = 5;
		}

		string str;
		if(numOfWords == 5)
		{
			cin >> str >> str;
			size_t found = str.find_first_of("'");
			name2 = str.substr(0,found);
			cin >> str;
		}
		else
		{
			cin >> str;
			//cout << "str = " << str << endl;
			size_t found = str.find_first_of("'");
			name2 = str.substr(0,found);
			//cout << "found = " << found << endl;
			cin >> str;
		}

		//cout << endl << "name1 = " << name1 << " name2 = " << name2 << " action = " << action << endl;

		if(name == name1)
		{
			if(vector_find(names,name2) != -1)
			{
				int pos = vector_find(names,name2);
				priority[pos] += score;
			}
			else
			{
				names.push_back(name2);
				priority.push_back(score);
			}
		}
		else if(name == name2)
		{
			if(vector_find(names,name1) != -1)
			{
				int pos = vector_find(names,name1);
				priority[pos] += score;
			}
			else
			{
				names.push_back(name1);
				priority.push_back(score);
			}
		}
		else
		{
			if(vector_find(names,name1) == -1)
			{	
				names.push_back(name1);
				priority.push_back(0);
			}
			if(vector_find(names,name2) == -1)
			{	
				names.push_back(name2);
				priority.push_back(0);
			}
		}

		num--;
	}

	FacetookPriorityWall(names,priority);
	return 0;
}
